#include "CTaskHelper.h"

namespace TB
{
	STask<void> CTaskHelper::Delay(UINT64 qwMilliSeconds)
	{
		auto& roCurThreadTimerContext = CCurThreadTimerContext::GetCurrent();
		auto sTaskProcessor = CreatePendingTask<void>();
		std::function<void()> cbFunc = [sTaskProcessor]() mutable
		{
			sTaskProcessor.Resolve();
		};
		auto& poTimerContext = roCurThreadTimerContext.GetTimerContext();
		if (poTimerContext == nullptr)
		{
			CThreadPool::StartTimer(qwMilliSeconds, cbFunc);
		}
		else
		{
			poTimerContext->StartTimer(qwMilliSeconds, cbFunc);
		}
		return sTaskProcessor.GetTask();
	}
}